package fhq.hcmute.qrcode;

import java.io.IOException;

import fhq.hcmute.qrcode.common.BinaryImage;
import fhq.hcmute.qrcode.common.BitMatrix;
import fhq.hcmute.qrcode.decoder.Decoder;
import fhq.hcmute.qrcode.detector.Detector;
import fhq.hcmute.qrcode.util.QRCodeException;

/**
 * @author Hien Nguyen Le
 * @Email: nglehien@gmail.com
 */
public class QRCodeReader {

	private BinaryImage binaryImage;
	private BitMatrix bitMatrix;

	public QRCodeReader(BinaryImage binaryImage) throws IOException {
		this.binaryImage = binaryImage;
	}

	public QRCode decode() throws QRCodeException {
		Detector detector = new Detector(this.binaryImage);
		this.bitMatrix = detector.detectBitMatrix();
		Decoder decoder = new Decoder();
		return decoder.decode(bitMatrix);
	}

	public BinaryImage getBinaryImage() {
		return binaryImage;
	}

	public void setBinaryImage(BinaryImage binaryImage) {
		this.binaryImage = binaryImage;
	}

	public BitMatrix getBitMatrix() {
		return bitMatrix;
	}

	public void setBitMatrix(BitMatrix bitMatrix) {
		this.bitMatrix = bitMatrix;
	}

}
